home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Utils / Software6 / Product8 / feedview-0.9.7-fx.xpi / chrome / feedview.jar / content / feedview.js < prev    next >
Text File  |  2005-03-25  |  7KB  |  281 lines

  1. /*
  2.  * Original author: Tom Germeau ( http://www.epigoon.com )
  3.  * If you want to use/modify this code please 
  4.  * contact the original author first.
  5.  */
  6.  
  7.  
  8.    var currSize;
  9.    var number ;
  10.    /*Notes: xsl:sort select="name"*/
  11.    
  12.    
  13.  
  14.    function setFeed()
  15.    {
  16.        var title = document.getElementsByTagName("h1")[0].textContent;
  17.        
  18.        document.title = document.getElementsByTagName("title")[0].textContent + " " +  title;
  19.    }
  20.  
  21.  
  22.     function xmlDate(In){
  23.       In = In.replace('Z', '+00:00')
  24.       var D = In.replace(/^(\d{4})-(\d\d)-(\d\d)T([0-9:]*)([.0-9]*)(.)(\d\d):(\d\d)$/, '$1/$2/$3 $4 $6$7$8');
  25.           //var D = In.replace(/^(\d{4})-(\d\d)-(\d\d)T([0-9:]*)([0-9:]*)([0-9:]*).*$/, '$1/$2/$3 $4 $6');
  26.           //var D = In.replace(/^(\d{4})-(\d\d)-(\d\d)T([0-9:]*)([.0-9]*)(.)(\d\d):(\d\d)$/, '$1/$2/$3 $4 $6$7$8');
  27.           D = Date.parse(D);
  28.           D += 1000*RegExp.$5;
  29.           return new Date(D);
  30.     
  31.     } 
  32.     
  33.  
  34.    function setDate(){
  35.  
  36.        try{
  37.        
  38.        
  39.         var found = false;
  40.        
  41.        
  42.        divs = document.getElementsByTagName("div");
  43.        for(i=0; i<divs.length; i++){
  44.        
  45.  
  46.                    d = divs[i].getAttribute("date");
  47.                    if(d )
  48.                    {
  49.                     found = true;
  50.                        if(d.indexOf("T"))
  51.                            d = xmlDate( d );
  52.                        else
  53.                            d = new Date( d );
  54.                        
  55.                        
  56.                        if(d instanceof Date){
  57.                            
  58.                            if(0)
  59.                                day = "Today";
  60.                            else{ 
  61.                                day = d.toGMTString();
  62.                                day = day.substring(0, 11);
  63.                            }
  64.                                
  65.                            divs[i].getElementsByTagName("span")[0].textContent = day + " @ " + lead(d.getHours()) +  ":" + lead(d.getMinutes());
  66.                        }
  67.                            
  68.                    }
  69.                
  70.            }
  71.  
  72.         if(!found){
  73.             document.getElementById("switchdate").style.display = "none";
  74.  
  75.             divs = document.getElementsByTagName("div");
  76.             for(i=0; i < divs.length; i++)
  77.                 if(divs[i].getElementsByTagName("span").length > 0 )
  78.                     if(divs[i].getElementsByTagName("span")[0].getAttribute("class") == "date")
  79.                     divs[i].getElementsByTagName("span")[0].style.display = "none";
  80.         }
  81.        }catch(ex){alert(ex);}
  82.    }
  83.  
  84.    function fixchars(txt)
  85.    {
  86.  
  87.         txt = txt.replace(/ /g,  " ");
  88.         txt = txt.replace(/&/g,  "&");
  89.         txt = txt.replace(/>/g,  ">");
  90.         txt = txt.replace(/</g,  "<");
  91.         txt = txt.replace(/"/g,  "'");
  92.         txt = txt.replace(/’/g, "'");
  93.         txt = txt.replace(/‘/g, "'");
  94.         txt = txt.replace(/—/g, "ù");
  95.         txt = txt.replace(/&/g, "&");
  96.         return txt;
  97.  
  98.    }
  99.  
  100.    function resize(maxSize, init){
  101.         var img = /<img([^>]*)>/g;
  102.         var imgArr; 
  103.         var im;
  104.            //number = 0;
  105.   
  106.            sl = document.getElementById("sizeslider");
  107.            sl.setAttribute("curpos", maxSize);
  108.           if(maxSize == currSize) return;
  109.        currSize = maxSize;
  110.     
  111.        try{
  112.        divs = document.getElementsByTagName("div");
  113.        for(i=0; i<divs.length; i++){
  114.  
  115.  
  116.                    if(init)
  117.                 {
  118.                     title = divs[i].getElementsByTagName("a");
  119.                     if(title.length > 0)
  120.                     {
  121.                         title = title[0];
  122.                         title.textContent = fixchars(title.textContent);
  123.                         title.textContent = title.textContent.replace(/<([^>]*)>/g, "");
  124.                     }
  125.                 }
  126.  
  127.                    txt = divs[i].getAttribute("description");
  128.                    if(txt != null){
  129.           
  130.                     txt = fixchars(txt);
  131.                     
  132.  
  133.                     txt = txt.replace(/<br[^\>]*>/g, "\n");
  134.                     txt = txt.replace(/<p[^\>]*>/g, "\n");
  135.  
  136.                     /*
  137.                        txt = txt.replace(/&#([0-9]+);/g, 
  138.                            function (str, n){
  139.                                //alert(n);
  140.                                try{
  141.                                //0alert("\u151");
  142.                                //alert( String.fromCharCode(("x" + n)) );
  143.                                return String.fromCharCode(parseInt(n));
  144.                                
  145.                                }catch(ex){alert(ex);}
  146.                                //return "\u8212";
  147.                            }
  148.                        
  149.                         );
  150.                         */
  151.  
  152.                        if(init){
  153.                     imgArr = new Array();
  154.                        img.lastIndex = 0;
  155.  
  156.                     while((im = img.exec(txt)) != null)
  157.                     {
  158.                         src = /\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i;
  159.                         im[0] = im[0].replace('border=', ''); // fix somtin?
  160.                         im[0] = im[0].replace('class=', ''); // fix somtin?
  161.                         imgsrc = src.exec(im[0]);
  162.                         imgArr.push(imgsrc[1]);
  163.  
  164.                     }
  165.         
  166.                     
  167.                     var o;
  168.                     for(im=0; im < imgArr.length; im++){
  169.  
  170.                         a = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
  171.                         a.setAttribute("href", imgArr[im]);
  172.                         o = document.createElementNS("http://www.w3.org/1999/xhtml", "img");
  173.                         a.setAttribute("class", "image");
  174.                         o.setAttribute("src", imgArr[im]);
  175.                         a.appendChild(o);
  176.                         divs[i].appendChild(a);
  177.  
  178.                     }
  179.                     }
  180.  
  181.                        txt = txt.replace(/<([^>]*)>/g, "");
  182.  
  183.  
  184.  
  185.                        ar = txt.split(" ");
  186.                        
  187.                     if(maxSize == 0) txt = "";
  188.                     
  189.                        if(maxSize < 100 && maxSize != 0){
  190.                        
  191.                            if(ar.length > maxSize){
  192.                                txt = "";
  193.                                for(x=0; x < maxSize ; x++){
  194.                                    txt += ar[x] + " ";
  195.                                }
  196.                                txt += " ..." ;
  197.                                
  198.                            }
  199.                               
  200.                             
  201.                        }
  202.                        /*
  203.                     if(    divs[i].getElementsByTagName("p")[0].textContent != txt)
  204.                         divs[i].getElementsByTagName("p")[0].textContent = txt;
  205.  
  206.                     */
  207.  
  208.                     currentP = divs[i].getElementsByTagName("p")[0];
  209.                     if(currentP != null){
  210.                     for(pc = currentP.childNodes.length; pc > 0; pc--){
  211.  
  212.                         currentP.removeChild(currentP.childNodes[0]);
  213.                     }
  214.  
  215.                        p = txt.split("\n");
  216.  
  217.  
  218.                     for(im=0; im < p.length; im++){
  219.                         if(p != ""){
  220.                         a = document.createElementNS("http://www.w3.org/1999/xhtml", "p");
  221.                         a.textContent = p[im];
  222.                         currentP.appendChild(a);
  223.                         }
  224.  
  225.                     }                    
  226.                     }
  227.  
  228.  
  229.                    }
  230.  
  231.  
  232.                
  233.            }
  234.  
  235.  
  236.  
  237.        }catch(ex){alert(ex);}
  238.    }
  239.  
  240.    
  241.  
  242.      function lead(In){
  243.          if(In < 10)
  244.              return "0" + In; 
  245.          else return In;
  246.      }
  247.  
  248.     
  249.     
  250.     function switchdate() {
  251.     
  252.         var s = document.getElementById("switchdate");
  253.         divs = document.getElementsByTagName("div");
  254.         
  255.         if(s.getAttribute("show") == "0"){
  256.             //s.setAttribute("show", 1);
  257.             s.textContent = "Show date";
  258.             for(i=0; i < divs.length; i++)
  259.                 if(divs[i].hasAttribute("date"))
  260.                     divs[i].getElementsByTagName("span")[0].style.display = "none";
  261.         }else {
  262.             //s.setAttribute("show", 0);
  263.             s.textContent = "Hide date";    
  264.             for(i=0; i < divs.length; i++)
  265.                 if(divs[i].hasAttribute("date"))
  266.                     divs[i].getElementsByTagName("span")[0].style.display = "inline";        
  267.         }
  268.         
  269.         
  270.     }
  271.      
  272.     function listObject(obj, s) {
  273.         var res = "List: " + obj + "\n";
  274.         for(var list in obj) {
  275.             if (list.indexOf(s) == -1)
  276.                 res += list + ", ";
  277.         }
  278.  
  279.         alert(res);
  280.     }
  281.